import Vue from 'vue'
import Vuex from 'vuex'
// 12.2 引入方法
import { setItem, getItem } from '@/utils/storage.js'
Vue.use(Vuex)

// 做数据持久化
const TOKEN_KEY = 'toutiao_user'
// const user = localStorage.getItem(TOKEN_KEY)

export default new Vuex.Store({
  state: {
    // 12.3 调用方法
    user: getItem(TOKEN_KEY)
  },
  getters: {
  },
  mutations: {
    // 11.2 定义方法
    setUser (state, payload) {
      state.user = payload
      setItem(TOKEN_KEY, payload)
    }
  },
  actions: {
  },
  modules: {
  }
})
